#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int main()
{
	int n;cin>>n;
	priority_queue<int,vector<int>,greater<int>> q;
	for(int i=1;i<=n;i++) 
	{
		int x;cin>>x;
		q.push(x);
	}
	int ret=0;
	while(q.size()>1)
	{
		int a=q.top();q.pop();
		int b=q.top();q.pop();
		int sum=a+b;
		ret+=sum;
		q.push(sum);
	}
	cout<<ret<<endl;
}